package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.ClientUserInfo;
import com.tenglong.teacher.ui.adapter.viewholder.LoginSelectOrganizationContentViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.LoginSelectOrganizationTitleViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.List;

/**
 * @author hdx on 2019/5/30.
 */
public class LoginSelectOrganizationAdapter extends RecyclerView.Adapter<BaseViewHolder<ClientUserInfo>> {

    private List<ClientUserInfo> userInfos;
    private LoginSelectOrganizationListener loginSelectOrganizationListener;

    public LoginSelectOrganizationAdapter(List<ClientUserInfo> userInfos){
        this.userInfos = userInfos;
    }

    @NonNull
    @Override
    public BaseViewHolder<ClientUserInfo> onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if (i==0){
            return new LoginSelectOrganizationTitleViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.select_organization_title,viewGroup,false));
        } else {
            return new LoginSelectOrganizationContentViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.select_organization_item,viewGroup,false),loginSelectOrganizationListener);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return userInfos.get(position).isSelectOrganizationTitle?0:1;
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<ClientUserInfo> clientUserInfoBaseViewHolder, int i) {
        clientUserInfoBaseViewHolder.setLayoutInfo(userInfos.get(i));
    }

    @Override
    public int getItemCount() {
        return userInfos.size();
    }

    public void setLoginSelectOrganizationListener(LoginSelectOrganizationListener loginSelectOrganizationListener){
        this.loginSelectOrganizationListener = loginSelectOrganizationListener;
    }


    public interface LoginSelectOrganizationListener{
        void onLoginSelectOrganizationListener(int position,ClientUserInfo info);
    }
}
